const { updateService, findService } = require('../services/aboutService');
const AppError = require('../utils/AppError');
const Controller = require('../utils/Controller');
const { toi } = require('../utils/tools');

class AboutController extends Controller {
	async getAbout(req, res, next) {
		await toi(findService(), res, next);
	}

	async setAbout(req, res, next) {
		const schema = req.joi.object({
			url: req.joi.string().required()
		});

		const { error } = await schema.validate(req.body);
		if (error) return next(new AppError(error, 401));

		await toi(updateService(req.body), res, next);
	}
}

module.exports = new AboutController();
